<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
</head>

<body>
</body>
<script>
  (function () {

    var port = 8888

    var config = {
      entry: {
        app: './src/main.js'
      },
      output: {
        path: path.resolve(__dirname, '../dist')
      },
      resolve: {
        extensions: ['.js','.vue','.json'],           // 不需后缀
        alias: {
          img: resolve(this.root_path, 'src/assets')
        }
      },
      module: {
        rules: [
          {
            test: /\.vue$/,
            loader: 'vue-loader',
            options: vueLoaderConfig
          },{
            test: /\.js$/,
            loader: 'babel-loader',
            include: [resolve('src'), resolve('test')]    // 对这两个文件夹下的js文件转义
          }
        ]
      },
      plugins: []
    }

    var env = {
      dev: true,
      pro: false
    }

    if (env.dev) {
      var app = new express()
      app.use(function* () {
        this.body = 'hello world'
      })
      var devConfig = {
        plugins: [
          new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html',
            inject: true
          })
        ]
      }
      var configs = merge(config, devConfig)
      const compiler = webpack(configs)
      app.use(devMiddleware(compiler))  // 热更新
      app.use(htoMiddleware(compiler))
      app.listen(port)
    } else {
      // 删除dist
      rm(path.join(), err => {
        proConfig = {
          plugins: [
            new webpack.optimize.UglifyJsPlugin({        //丑化压缩代码, 只有生产环境下才需要
              sourceMap: true
            })
          ]
        }
        var configs = merge(config, proConfig)
        webpack(configs)
      })
    }


  })()
</script>

</html>